package com.du.algorithm.primary;


import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONUtil;
import lombok.Data;

import java.io.BufferedReader;
import java.io.File;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @desc:
 * @author: shuangdu
 * @date: 2022/1/28
 * @since: 1.8
 */
public class LoadJson {

    public static void main(String[] args) throws Exception{
        Thread.sleep(2000);
        URL url = ClassLoader.getSystemResource("a.json");
        File file = new File(url.getFile());
        BufferedReader reader = FileUtil.getReader(file, "utf-8");
        StringBuilder sb = new StringBuilder();
        reader.lines().forEach(sb::append);
//        List<A> arr = JSONUtil.toBean(sb.toString(), new TypeReference<List<A>>() {}, false);
//        arr.forEach(i -> System.out.println(i.userLoginName));

        // 学校信息
        Result<SchoolInfo> result = JSONUtil.toBean(sb.toString(), new TypeReference<Result<SchoolInfo>>() {}, false);
        result.data.forEach(i -> System.out.println(String.format("%s %s %s %s %s", i.getProvinceName(), i.getCityName(), i.getDistrictName(), i.getValue(), i.getName())));


//        Set<String> set = new HashSet<>();
//        reader.lines().forEach(s -> {
//            set.addAll(Arrays.asList(s));
//        });
//        List<List<String>> split = ListUtil.split(new ArrayList<>(set), 3000);
//        for (List<String> s : split) {
//            StringBuilder sb1 = new StringBuilder();
//            for (String ss : s) {
//                sb1.append(ss)
//                        .append(",")
//                        .append("\n");
//            }
//            System.out.println(sb1.substring(0, sb1.length() -2));
//            Thread.sleep(20000);
//        }
        System.out.println("结束=====");

    }


    @Data
    static class A {
        private String userLoginName;
    }

    @Data
    static class Result<T> {
        private String message;
        private List<T> data;
    }

    @Data
    static class SchoolInfo {
        private String provinceId;
        private String provinceName;
        private String cityId;
        private String cityName;
        private String districtId;
        private String districtName;
        private String value;
        private String name;
    }
}
